<?php


namespace app\api\controller;

use app\api\model\Member;

class Base
{
    public function register()
    {
        $mobile = input('get.mobile');//接收GET键名为name的值并且赋给变量name
        $password = input('get.password');
        $nickname = input('get.nickname');
        if (empty($mobile)) output_error('手机号不能为空');
        if (empty($password)) output_error('密码不能为空');
        if (empty($nickname)) output_error('昵称不能为空');
        if (strlen($mobile) != 11) output_error('手机号码格式不正确');
        if (Member::register($mobile,$password,$nickname)) output_data('注册成功');
        output_error('失败');
    }
    public function login()
    {
        $mobile = input ('get.mobile');
        $password = input('get.passwored');
        if(empty($mobile)) output_error('手机号不能为空');
        if(empty($password)) output_error('密码不能为空');

        $condition = array();
        $condition[] =['member_mobile','=',$mobile];
        $condition[] =['member_password','=',md5($password)];
        $member = Member::where($condition)->find();
        if (empty($member)) output_error('账号或密码错误');

        $token = md5($member['member_id'].time());
        $data = array();
        $data['member_id'] = $member['member_id'];
        $data['token_content'] = $token;
        $data['device_model'] = $model;
        $data['end_time'] = time() + 65535;
        $data['add_time'] = time();
        MemberToken::insert($data);
        output_data($token);
    }
}
